package com.example.javamaday.leetcode;

import java.util.Stack;

public class LeetCodeTest0232 {

    public static void main(String[] args) {

    }

    class MyQueue {

        Stack<Integer> pushStack;
        Stack<Integer> peekStack;

        /**
         * Initialize your data structure here.
         */
        public MyQueue() {
            pushStack = new Stack<>();
            peekStack = new Stack<>();
        }

        /**
         * Push element x to the back of queue.
         */
        public void push(int x) {
            pushStack.push(x);
        }

        /**
         * Removes the element from in front of queue and returns that element.
         */
        public int pop() {
            if (peekStack.isEmpty()) {
                while (!pushStack.isEmpty()) {
                    peekStack.push(pushStack.pop());
                }
            }
            return peekStack.pop();
        }

        /**
         * Get the front element.
         */
        public int peek() {
            if (peekStack.isEmpty()) {
                while (!pushStack.isEmpty()) {
                    peekStack.push(pushStack.pop());
                }
            }
            return peekStack.get(peekStack.size() - 1);
        }

        /**
         * Returns whether the queue is empty.
         */
        public boolean empty() {
            return peekStack.isEmpty() && pushStack.isEmpty();
        }
    }
}
